//
//  SKTableTableViewController.swift
//  玩玩,传递
//
//  Created by yanli on 16/7/12.
//  Copyright © 2016年 mountainPassCell. All rights reserved.
//

import UIKit

// 重用标识符
// one
private let SKTableViewCellIdentifier = "zhuxian"
// two
private let twoCellIdentifier = "yixue"
// san
private let sanCellIdentifier = "xiaobing"
// four
private let fourCellIdentifier = "dou"
// five 
private let fiveCellIdentifier = "shen"



//主页
class SKTableViewController: UITableViewController {

    
    override func loadView() {
        super.loadView()
        
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        navigationItem.title = "首页"
        
        navigationController?.navigationBar.barTintColor = UIColor.yellowColor()
        
        view.backgroundColor = UIColor.grayColor()
        
        tableView.bounces = false
        
        // 设置 TableView 及相关的操作
        setTableView()

        

    }

    
    // 设置 TableView 及相关的操作
    private func setTableView() {
        // 注册cell
        tableView.registerNib(UINib(nibName: "SKMainTableViewCell", bundle: nil), forCellReuseIdentifier: SKTableViewCellIdentifier)
        
        tableView.registerNib(UINib(nibName: "SKTwoTableViewCell", bundle: nil), forCellReuseIdentifier: twoCellIdentifier)
        
        tableView.registerNib(UINib(nibName: "sanTableViewCell", bundle: nil), forCellReuseIdentifier: sanCellIdentifier)
        
        tableView.registerNib(UINib(nibName: "fourTableViewCell", bundle: nil), forCellReuseIdentifier: fourCellIdentifier)
        
        tableView.registerNib(UINib(nibName: "fiveTableViewCell", bundle: nil), forCellReuseIdentifier: fiveCellIdentifier)
        
        
        
        
        //        //  设置自动行高, 通过约束设置高度
        //        tableView.rowHeight = UITableViewAutomaticDimension
        //        //  预估行高越接近真实高度越好
        //        tableView.estimatedRowHeight = 150
        
        
        
    }
    
    

    
    
    // MARK: - Table view data source

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 5
    }

    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
  
        let cell = UITableViewCell(style: .Default, reuseIdentifier: SKTableViewCellIdentifier)
        
        
        if indexPath.row == 0 {
            let oneCell: SKMainTableViewCell = tableView.dequeueReusableCellWithIdentifier(SKTableViewCellIdentifier, forIndexPath: indexPath) as! SKMainTableViewCell

            oneCell.wantController = { [weak self] in
                
                
                let zhuXianVC = SKZhuXianViewController()
                
                self!.navigationController!.pushViewController(zhuXianVC, animated: true)
                
                }
            
            return oneCell
          
            
            
        } else if indexPath.row == 1 { //
            
            let twoCell: SKTwoTableViewCell = tableView.dequeueReusableCellWithIdentifier(twoCellIdentifier, forIndexPath: indexPath) as! SKTwoTableViewCell
            
            
 
            
            return twoCell
        } else if indexPath.row == 2 {
            
            let sanCell: sanTableViewCell = tableView.dequeueReusableCellWithIdentifier(sanCellIdentifier, forIndexPath: indexPath) as! sanTableViewCell
  
            return sanCell
        } else if indexPath.row == 3 {
            
            let fourCell: fourTableViewCell = tableView.dequeueReusableCellWithIdentifier(fourCellIdentifier, forIndexPath: indexPath) as! fourTableViewCell
            
            return fourCell
        } else if indexPath.row == 4 {
            
            let fiveCell: fiveTableViewCell = tableView.dequeueReusableCellWithIdentifier(fiveCellIdentifier, forIndexPath: indexPath) as! fiveTableViewCell
            
            return fiveCell
        }

        return cell
        
    }
    

    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return 200
    }
    
    
    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        
        
        if indexPath.row == 0 {
            let clickCellVC = SKViewController()
            
            self.navigationController!.pushViewController(clickCellVC, animated: false)

        } else if indexPath.row == 1 {
            
            let twoCellVC = TwoViewController()
            
            self.navigationController!.pushViewController(twoCellVC, animated: false)
            
        } else if indexPath.row == 2 {
            
            let sanCellVC = sanViewController()
            
            self.navigationController!.pushViewController(sanCellVC, animated: false)
            
        } else if indexPath.row == 3 {
            
            let fourCellVC = fourViewController()
            
            self.navigationController!.pushViewController(fourCellVC, animated: false)
            
            
        } else if indexPath.row == 4 {
            
            let fiveCellVC = fiveViewController()
            
            self.navigationController!.pushViewController(fiveCellVC, animated: false)
        }
        
        
        
        
        
}
    
    
    
    
   

}
